home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
183
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
3KB
Path: solon.com!not-for-mail
From: diamond@tko.dec.com (Norman Diamond)
Newsgroups: comp.lang.c.moderated,comp.std.c
Subject: Re: Function returning structure
Followup-To: comp.std.c
Date: 25 Jan 1996 06:34:13 -0600
Organization: Digital Equipment Corporation Japan , Tokyo
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4e7tc5$mk@solutions.solon.com>
References: <4e2ki8$l0k@solutions.solon.com> <4e5p00$6g9@solutions.solon.com>
Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
NNTP-Posting-Host: solutions.solon.com
In article <4e5p00$6g9@solutions.solon.com>, tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya) writes:
>In article <4e2ki8$l0k@solutions.solon.com> bnelson@netcom.com (Bob
>Nelson) writes:
>>(It goes on to add -- in its example text -- that f().x
>>is a valid postfix expression though not an lvalue, presuming that
>>f is a function returning a structure and that x is member).
>>With that in mind -- does the standard have anything that might
>>disqualify member selection (in a non-assignment context) if that
>>member is of type array and that structure is returned by a function?
>There is nothing wrong selecting that element. However, this element
>does not decay to a pointer to its first element. As a result, very
>few things can be done to it, except casting it to type void.
A perverse programmer could apply sizeof to it.
>Is the following strictly conformant?
> #include <stdio.h>
> #include <stdarg.h>
> typedef struct a {char b[5];} a;
> typedef char c[5];
> int f(char *fmt, ...) { char *s;
> va_list ap;
> va_start(ap,x);
> s = va_arg(ap, c);
I cannot find any reason that the returned result of va_arg would be an
lvalue. I believe that this example produces a non-lvalue array, which
does not decay to a pointer and cannot be assigned to s.
> return printf(fmt,s); }
Mu. But let's delete all mentions of s and printf, and try this instead:
return some_other_vararg_f(fmt, va_arg(ap, c));
>i.e. can non-lvalue arrays be passed to a function and accessed by
>the stdarg macros there?
I think that the standard permits it, and the standard needs to be fixed.
ANSI Classic section 3.3.2.2, page 41 lines 33 to 35: "In preparing for
the call to a function, the arguments are evaluated, and each parameter is
assigned the value of the corresponding argument." Then some_other_vararg_f
can use va_arg to get a copy of the thing, but there's still not much else
that can be done with it. I think the standard needs an additional
constraint, that each argument shall have a type permitted for the right
operand of a simple assignment.
--
<< If this were the company's opinion, I would not be allowed to post it. >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer